<template>
  <view class="product-item">
    <image class="product-image" :src="product.image" mode="aspectFill"></image>
    <view class="product-info">
      <view class="product-title">{{ product.title }}</view>
      <view class="product-meta">
        <text class="product-sold">已拼{{ product.soldCount }}件</text>
      </view>
      <view class="product-bottom">
        <view class="product-price">
          <text class="currency">¥</text>
          <text class="amount">{{ product.price }}</text>
        </view>
        <view class="product-action" @click.stop="onUnfavorite">
          <text class="action-text">取消收藏</text>
        </view>
      </view>
    </view>
    <view class="group-tag" v-if="product.groupSize">
      <text>{{ product.groupSize }}人团</text>
    </view>
  </view>
</template>

<script setup>
import { defineProps, defineEmits } from 'vue';

const props = defineProps({
  product: {
    type: Object,
    required: true
  }
});

const emit = defineEmits(['unfavorite']);

const onUnfavorite = () => {
  emit('unfavorite', props.product.id);
};
</script>

<style>
.product-item {
  position: relative;
  display: flex;
  background-color: #fff;
  border-radius: 12px;
  margin-bottom: 15px;
  padding: 15px;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.05);
}

.product-image {
  width: 100px;
  height: 100px;
  border-radius: 8px;
  background-color: #f2f2f2;
}

.product-info {
  flex: 1;
  padding-left: 15px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}

.product-title {
  font-size: 15px;
  color: #333;
  line-height: 1.4;
  font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

.product-meta {
  font-size: 12px;
  color: #999;
  margin: 8px 0;
}

.product-bottom {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.product-price {
  display: flex;
  align-items: baseline;
  color: #FF6633;
}

.currency {
  font-size: 14px;
}

.amount {
  font-size: 20px;
  font-weight: bold;
}

.product-action {
  background-color: #FF6633;
  padding: 6px 12px;
  border-radius: 20px;
}

.action-text {
  font-size: 12px;
  color: #fff;
}

.group-tag {
  position: absolute;
  left: 15px;
  top: 15px;
  background-color: #FF6633;
  color: #fff;
  font-size: 12px;
  padding: 2px 8px;
  border-radius: 12px;
  z-index: 1;
}
</style> 